package com.hxx.day8a.controller;

import com.hxx.day5example.domain.Emp;
import com.hxx.day8a.common.HxxUtils;
import com.hxx.day8a.service.EmpService;
import com.hxx.day8a.service.impl.EmpServiceImpl;

import java.util.List;
import java.util.Scanner;

public class EmpController {
    private EmpService empService = new EmpServiceImpl();

    public void save(Scanner scanner){
        Emp emp = new Emp();
        emp.setId(HxxUtils.getKey());
        System.out.println("请输入员工姓名");
        emp.setUsername(scanner.next());
        System.out.println("请输入员工性别");
        emp.setSex(scanner.next());
        System.out.println("请输入员工年龄");
        emp.setAge(scanner.nextInt());
        //调用保存方法
        empService.save(emp);
    }
    public void update(Scanner scanner){
        System.out.println("请输入员工id");
        Emp emp = new Emp();
        emp.setId(scanner.nextLong());
        System.out.println("请输入员工姓名");
        emp.setUsername(scanner.next());
        System.out.println("请输入员工性别");
        emp.setSex(scanner.next());
        System.out.println("请输入员工年龄");
        emp.setAge(scanner.nextInt());
        //调用修改方法
        empService.update(emp);
    }
    public void delete(Scanner scanner){
        System.out.println("请输入员工id");
        empService.delete(scanner.nextLong());
    }
    public void findAll(){
        List<Emp> all = empService.findAll();
        System.out.println( all);
    }
}

















